package tabuImpl.util;

import java.lang.reflect.Array;
import java.util.Random;

public  class TabuUtil {
    public static int []randomChoice(int n){//不包括n
        int [] data=new int[n];
        return TabuUtil.randomChoiceLowAndHigh(0,n-1);

    }
    public static int []randomChoiceLowAndHigh(int low,int high){//左右皆是闭区间
        int [] data=new int[high-low+1];
        for(int i=low;i<=high;i++)
            data[i]=i;
        return TabuUtil.randomChoiceFromArray(data);

    }
    public static int []randomChoiceFromArray(int[] rawData){
        int [] data= rawData.clone();
        int n=data.length;
        Random r= new Random();
        for(int i=0;i<n;i++){
            int nextIndex=r.nextInt(n-i);
            int temp=data[nextIndex];
            data[nextIndex]=data[i];
            data[i]=temp;
        }

        return data;

    }
    public static void swap(int[] data,int a,int b){
        int t=data[a];
        data[a]=data[b];
        data[b]=t;
    }
}
